<template>
  <div id="cluereport">
    <el-dialog
      :title="dialogtitle"
      :visible.sync="porjectEidtFormVisible"
      width="98%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false">
      <projectEdit @dialogHide="saveSuccess" :taskId="$route.params.id" :id="projectId" :readOnly="readOnly" :timestamp="timestamp"></projectEdit>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/meeting' }">司内会议</el-breadcrumb-item>
      <el-breadcrumb-item >填报</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs" style="height:90px;overflow:hidden">
    <!--工具条-->
      <h1>司内会议名称：{{project}}</h1>
      <el-button type="warning" @click="submitItem" icon="el-icon-s-promotion" style="float:right;margin:10px;">提交</el-button>
      <el-button type="success" @click="addnew" icon="el-icon-plus" style="float:right;margin:10px 0;">新建</el-button>
      <el-form :inline="true" :model="filters" style="margin:10px;float:left">
        <div>
          <el-form-item label="名称">
            <el-input v-model="filters.key" placeholder="关键字" @keyup.enter.native="searchItem"></el-input>
          </el-form-item>
          <el-form-item label="状态">
              <el-select v-model="filters.status" placeholder="请选择" style="width:100px">
                <el-option label="全部" value=""></el-option>
                <el-option v-for="(item, index) in statusdic" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchItem" icon="el-icon-search">查询</el-button>
          </el-form-item>
        </div>
      </el-form>
    </section>
    <section class="unitbox" style="margin-top:10px">
    <!-- <section style="margin-top:10px"> -->
      <!--列表-->
      <el-table :data="list" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        >
        <el-table-column type="selection" width="40" :selectable="canSelect" />
        <!-- <el-table-column type="index" label="序号" width="60" align="center" class-name="tableth">
        </el-table-column> -->
        <el-table-column label="名称" prop="title" show-overflow-tooltip />
        <!-- <el-table-column label="附件个数" prop="filesNum" width="100" v-if="!project.customType" >
          <template slot-scope="scope">
            {{scope.row.state===1?scope.row.filesNum:''}}
          </template>
        </el-table-column> -->
        <el-table-column label="状态" prop="submitDate" width="100" align="center">
          <template slot-scope="scope">
            <el-tooltip
              v-if="scope.row.status===2"
              placement="top"
              style="font-zie:16px"
              :content="'退回时间：'+scope.row.backTime+' 退回原因：'+scope.row.reason"
              >
              <el-tag type="warning" effect="dark" style="margin:10px 0"><b>退回</b></el-tag>
            </el-tooltip>
            <el-tag v-else-if="scope.row.status===1" type="success" style="margin:10px 0" effect="dark"><b>已提交</b></el-tag>
            <el-tag v-else-if="scope.row.status===0" type="info" style="margin:10px 0"><b>未提交</b></el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button @click="detail(scope.row.id)" type="primary" size="small" v-if="scope.row.status===1">查看</el-button>

            <el-dropdown split-button type="primary" @click="detail(scope.row.id)" size="small" v-else>
              查看
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(scope.row.id)" >修改</el-dropdown-item>
                <el-dropdown-item @click.native="remove(scope.row.id)" >删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
<!--
            <el-dropdown style="margin-left:5px" v-if="scope.row.status!==1">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleEdit(scope.row.id)" >修改</el-dropdown-item>
                <el-dropdown-item @click.native="remove(scope.row.id)" >删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown> -->
          </template>
        </el-table-column>
      </el-table>
    </section>
  </div>
</template>

<script>
import projectEdit from './detail'
export default {
  components: {
    projectEdit
  },
  data () {
    return {
      ids: [],
      readOnly: true,
      projectId: null,
      dialogtitle: '新建',
      timestamp: '',
      porjectEidtFormVisible: false,
      porjectEidtFormLoading: false,
      statusdic: [{id: 0, name: '未提交'}, {id: 1, name: '已提交'}, {id: 2, name: '已退回'}],
      filters: {
        key: '',
        status: null
      },
      meetingAdmin: false,
      viewtype: 1,
      project: '',
      listLoading: true,
      tableHeight: 100,
      list: [
      ],
      changeSizeFlag: false,
      unitName: '',
      projectDataId: '',
      backReason: '',
      formShowVisible: false,
      submitLoading: false
    }
  },
  methods: {
    canSelect (row) {
      if (row.status !== 1) { // 202106
        return true
      } else {
        return false
      }
    },
    saveSuccess () {
      this.porjectEidtFormVisible = false
      this.getList()
    },
    submitItem () {
      if (this.ids.length === 0) {
        this.$message({
          message: '至少选择一项材料',
          type: 'error'
        })
        return false
      }
      this.$confirm('确认提交吗?', '提示', {
        type: 'success'
      }).then(() => {
        this.$http.post(this.$http.defaults.meetingAPI + `api/meetingBusItem/submitItem`, {ids: this.ids.map(item => item.id)}).then(response => {
          if (response.data.success === true) {
            this.$message({
              message: '提交成功',
              type: 'success'
            })
          } else {
            console.log('提交失败:' + response.data.message)
            this.$message({
              message: '提交失败:' + response.data.message,
              type: 'error'
            })
          }
          this.getList()
        })
      }).catch(() => {
      })
    },
    addnew () {
      this.readOnly = false
      this.dialogtitle = '新建'
      this.projectId = 0
      this.timestamp = new Date().getTime()
      this.porjectEidtFormVisible = true
    },
    detail (id) {
      this.readOnly = true
      this.dialogtitle = '查看'
      this.projectId = id
      this.timestamp = new Date().getTime()
      this.porjectEidtFormVisible = true
    },
    handleEdit (id) {
      this.readOnly = false
      this.dialogtitle = '修改'
      this.projectId = id
      this.timestamp = new Date().getTime()
      this.porjectEidtFormVisible = true
    },
    remove (id) {
      this.$confirm('确认删除该信息吗?', '提示', {
        type: 'error'
      }).then(() => {
        this.$http.post(this.$http.defaults.meetingAPI + `api/meetingBusItem/remove`, {ids: [id]}).then(response => {
          if (response.data.success === true) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            console.log('删除失败:' + response.data.message)
            this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
          this.getList()
        })
      }).catch(() => {
      })
    },
    searchItem () {
      this.pageNum = 1
      this.getList()
    },
    handleSelectionChange (val) {
      this.ids = val
    },
    getList () {
      this.listLoading = true
      this.$http
        .get(this.$http.defaults.meetingAPI + `api/meetingBusTask/getById?id=` + this.$route.params.id)
        .then(response => {
          this.project = response.data.result.name
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .post(this.$http.defaults.meetingAPI + `api/meetingBusItem/queryList`, {taskId: this.$route.params.id, onlySelf: true, status: this.filters.status, title: this.filters.key})
        .then(response => {
          this.list = response.data.result
          this.listLoading = false
        })
        .catch(error => {
          this.listLoading = false
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      let myheight = 255

      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - myheight
      })
    }
  },
  mounted () {
    this.getList()
    this.tableresize(this)
    window.onresize = () => {
      this.tableresize(this)
    }
  }
}
</script>
<style>
#cluereport .el-drawer__wrapper{
  width: 100%;
  height: 100%;
  position: fixed !important;
  overflow: hidden;
}
  .unitbox .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .unitbox .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #cluereport .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }
</style>
<style scoped>
  #cluereport .el-button{
    color:#fff !important;
  }
  #cluereport h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #cluereport .wboxs{
    width: 100%;
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
    padding:0;
  }
  .unitbox{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
